<template>
  <page-wrap back hide-tab title="面试结果" stay-still :bg-color="uNavColor" >
    <view>
      <InterViewNavbg/>
      <view class="search">
        <u-search placeholder="请输入面试标题" class="library-u-search" v-model="keyword"  height="80" bg-color="#FFFFFF;"  maxlength="20"
          :show-action="true" :clearabled="false"  @search="handleSearch"  @custom="handleSearch"></u-search>
      </view>
    </view>
    
    <view>
      <scroll-view  class="scrollView" scroll-y enable-flex @scrolltolower="loadMore" 
          :refresher-triggered="triggered">
          <InterviewCell
            v-for="(item, index) in list"
            :key="index"
            :itemObj="item"
            btnTitle="查看详情"
            @cellTap="clickCell"
            @interviewBtn="clickCell"
          />
          <u-loadmore
            v-if="list.length>0 || !loaded"
            class="list-more"
            :status="moreLoading"
            :load-text="loadText"
          />
          <Empty
            v-if="loaded && list.length<=0"
            :baseImg="emptyImg"
            text="暂无数据"
            :fontWeight="400"
          />
      </scroll-view>
    </view>
  </page-wrap>
</template>

<script>
import Empty from '@/components/Empty.vue'
import InterviewCell from "./components/InterviewCell.vue";
import { getCompanyInterviewData } from "@/api/modules/company.js";
import InterViewNavbg from "./components/InterViewNavbg.vue";
export default {
   components: {
    Empty,
    InterviewCell,
    InterViewNavbg
  },
    data() {
    return {
      keyword: "",
      list: [],
      companyId: uni.getStorageSync("company-id"),
      pageParams: {
        pageNo: 1,
        pageSize: 10,
      },
      emptyImg: this.$imgBaseSelf + 'common/empty.png',
      searchIcon: this.$imgBaseSelf + "common/search.png",
      finished: false,
      loading: false,
      moreLoading: "loadmore",
      loadText: {
        loadmore: "加载更多",
        loading: "加载中",
        nomore: "已经到底啦",
      },
      loaded: false,
    }
  },
  mounted(){
    this.getData(false);
  },
  methods:{

    loadMore() {
      this.getData(true);
    },
    onRestore() {
      this.triggered = false;
      this._triggered = false;
    },
    onRefresh() {
      if (this._triggered) return;
      this._triggered = true;

      if (!this.triggered) {
        this.triggered = true;
      }
      this.getData(false);
    },
     getData(isMore) {
      if (!this.companyId) return;
      if (this.moreLoading == "loading" ) return;
      if(this.moreLoading == "nomore" && isMore){
          return;
      }
      if(!isMore){
        // 刷新数据
        this.pageParams.pageNo = 1;
      }
      const params = {
        queryType:"started",
        interviewTitle:this.keyword,
        pageNo: this.pageParams.pageNo,
        pageSize: this.pageParams.pageSize,
        companyId: this.companyId,
      };
      this.moreLoading = "loading"; 
      getCompanyInterviewData(params)
        .then((res) => {
          this.moreLoading = "loadmore";
          this.loaded = true;
          if (res.code == 200) {
            if (isMore) {
              this.list.push(...res.data);
            } else {
              this.list = res.data;
            }
            this.pageParams.pageNo++;
            if (this.pageParams.pageNo > res.pageparam.pages) {
              this.moreLoading = "nomore";
            }
          } else {
            this.moreLoading = "nomore";
            uni.showToast({
              title: res.status_desc,
              icon: "none",
            });
          } 
        })
        .catch((e) => {
          console.log(e);
          this.moreLoading = "nomore";
        })
        .finally(() => {
          this.triggered = false;
          this._triggered = false;
        });
    },
    handleSearch(value){
      this.keyword=value;
      this.getData(false);
    },

    clickCell(item) {
      let data = JSON.stringify(item);
      uni.navigateTo({
        url:"/pagesSub/companyCenter/interviewAI/interviewScore?data=" + data,
      });
    },
  }
};
</script>

<style lang="scss" scoped>

.search{
  margin: 32rpx 32rpx 10rpx;
}

.scrollView{
  box-sizing: border-box;
  height:calc(100vh - 220rpx);
}
</style>